package com.example.peibei.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.dingtao.common.bean.HomeBannerCate;
import com.dingtao.common.bean.Work;
import com.dingtao.common.core.WDActivity;
import com.dingtao.common.util.UIUtils;
import com.example.peibei.R;
import com.example.peibei.ui.adapter.ChooseWorkAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class ChooseWordActivity extends WDActivity {
    @BindView(R.id.rv_cate)
    RecyclerView rv_cate;

    private String job = "计算机/互联网/通信";

    List<Work> works = new ArrayList<>();
    private ChooseWorkAdapter chooseCateAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_choose_work;
    }

    @Override
    protected void initView() {
        rv_cate.setLayoutManager(new LinearLayoutManager(this));
        chooseCateAdapter = new ChooseWorkAdapter(works);
        rv_cate.setAdapter(chooseCateAdapter);
        addWorks();
        chooseCateAdapter.notifyDataSetChanged();
        chooseCateAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                Work data = works.get(position);
                if (!data.isChoosed()) {
                    data.setChoosed(true);
                    job = data.getName();
                }
                for (int i = 0; i < works.size(); i++) {
                    Work item = works.get(i);
                    if (position != i) {
                        item.setChoosed(false);
                    }
                }
                chooseCateAdapter.notifyDataSetChanged();
            }
        });
    }

    private void addWorks() {
        works.add(new Work("计算机/互联网/通信"));
        works.add(new Work("生产/工艺/制造"));
        works.add(new Work("商业/服务业/个体经营"));
        works.add(new Work("金融/投资/银行/保险"));
        works.add(new Work("文化/广告/传媒"));
        works.add(new Work("娱乐/艺术/表演"));
        works.add(new Work("医疗/护理/制药"));
        works.add(new Work("教育/培训"));
        works.add(new Work("律师/法务"));
        works.add(new Work("公务员/事业单位"));
        works.add(new Work("学生/研究生"));
        works.add(new Work("其他"));
    }

    @OnClick(R.id.iv_back)
    public void back() {
        finish();
    }

    @OnClick(R.id.tv_next)
    public void save() {
        Intent i = new Intent();
        i.putExtra("job", job);
        setResult(3, i);
        finish();
    }

    @Override
    protected void destoryData() {

    }
}
